﻿using System;
using System.Collections.Generic;
using System.Linq;
using Gizmox.WebGUI.Common.Resources;
using Gizmox.WebGUI.Forms;

namespace Bronze.ReportBuilder.Toolbox.Controls
{

    public interface IToolboxItem
    {
        List<string> TrackProperties
        {
            get;
            set;
        }

        bool ShowBorder
        {
            get;
            set;
        }

        string ControlName { get; }

        Type ControlType { get; }

        IconResourceHandle Icon
        {
            get;
        }

        Postion GetResizeBoxState(Control c);
        
        Control Create(string name);
    }

    [Serializable]
    public abstract class BaseToolboxItem : IToolboxItem
    {
        private List<string> _serializeProps = new List<string>() { "Name", "Size", "Location" };
        public virtual List<string> TrackProperties
        {
            get { return _serializeProps; }
            set { _serializeProps = value; }
        }

        public virtual bool ShowBorder
        {
            get;
            set;
        }
        public abstract string ControlName { get; }

        public abstract Type ControlType { get; }

        public virtual IconResourceHandle Icon
        {
            get
            {
                return new IconResourceHandle("Toolbox.Control_Control.png");
            }
        }

        public virtual Postion GetResizeBoxState(Control c)
        {
            return Postion.All;
        }
        

        public abstract Control Create(string name);
    }

    #region TextBox
    [Serializable]
    public class TextBoxItem : BaseToolboxItem
    {
        public override Type ControlType
        {
            get { return typeof(TextBox); }
        }

        public override IconResourceHandle Icon
        {
            get
            {
                return new IconResourceHandle("Toolbox.Control_TextBox.png");
            }
        }

        public override Control Create(string name)
        {
            var size = new System.Drawing.Size(100, 21);
            return new TextBox { Size = size, Name = name };
        }
        
        public override string ControlName
        {
            get { return "TextBox"; }
        }
    } 
    #endregion

    #region Label

    [Serializable]
    public class LabelBoxItem : BaseToolboxItem
    {
        public override Type ControlType
        {
            get { return typeof(Label); }
        }

        public override string ControlName
        {
            get { return "Label"; }
        }

        public override IconResourceHandle Icon
        {
            get
            {
                return new IconResourceHandle("Toolbox.Control_TextBlock.png");
            }
        }

        public override Control Create(string name)
        {
            var size = new System.Drawing.Size(35, 13);

            TrackProperties.Add("AutoSize");
            TrackProperties.Add("Text");
            return new Label { Name = name, AutoSize = true, Size = size, Text = name };
        }

        public override Postion GetResizeBoxState(Control c)
        {
            var label = c as Label;
            if (label != null)
            {
                if (label.AutoSize)
                {
                    return Postion.None;
                }
            }
            return base.GetResizeBoxState(c);
        }

    } 
    #endregion

    #region LinkLabel
    [Serializable]
    public class LinkLabelBoxItem : BaseToolboxItem
    {
        public override Type ControlType
        {
            get { return typeof(LinkLabel); }
        }

        public override string ControlName
        {
            get { return "LinkLabel"; }
        }

        public override IconResourceHandle Icon
        {
            get
            {
                return new IconResourceHandle("Toolbox.Control_LinkLabel.png");
            }
        }

        public override Control Create(string name)
        {
            var size = new System.Drawing.Size(35, 13);

            TrackProperties.Add("AutoSize");
            TrackProperties.Add("Text");
            return new LinkLabel { Name = name, AutoSize = true, Size = size, Text = name };
        }

        public override Postion GetResizeBoxState(Control c)
        {
            var label = c as LinkLabel;
            if (label != null)
            {
                if (label.AutoSize)
                {
                    return Postion.None;
                }
            }
            return base.GetResizeBoxState(c);
        }

    } 
    #endregion

    #region ComboBox

    [Serializable]
    public class ComboBoxItem : BaseToolboxItem
    {
        public override Type ControlType
        {
            get { return typeof(ComboBox); }
        }

        public override string ControlName
        {
            get { return "ComboBox"; }
        }

        public override IconResourceHandle Icon
        {
            get
            {
                return new IconResourceHandle("Toolbox.Control_ComboBox.png");
            }
        }

        public override Control Create(string name)
        {
            var size = new System.Drawing.Size(100, 21);

            return new ComboBox { Size = new System.Drawing.Size(100, 21), Name = name };
        }

    } 
    #endregion

    #region Button
    [Serializable]
    public class ButtonItem : BaseToolboxItem
    {
        public override Type ControlType
        {
            get { return typeof(Button); }
        }

        public override string ControlName
        {
            get { return "Button"; }
        }

        public override IconResourceHandle Icon
        {
            get
            {
                return new IconResourceHandle("Toolbox.Control_Button.png");
            }
        }

        public override Control Create(string name)
        {
            var size =  new System.Drawing.Size(75, 23);
            TrackProperties.Add("Text");
            return new Button {Size =size, Name = name, Text = name};
        }

        public override Postion GetResizeBoxState(Control c)
        {
            var btn = c as Button;
            if (btn != null)
            {
                if (btn.AutoSize)
                {
                    return Postion.None;
                }
            }
            return base.GetResizeBoxState(c);
        }

    } 
    #endregion

    #region ListBox

    [Serializable]
    public class ListBoxItem : BaseToolboxItem
    {
        public override Type ControlType
        {
            get { return typeof(ListBox); }
        }

        public override string ControlName
        {
            get { return "ListBox"; }
        }

        public override IconResourceHandle Icon
        {
            get
            {
                return new IconResourceHandle("Toolbox.Control_ListBox.png");
            }
        }

        public override Control Create(string name)
        {
            var size = new System.Drawing.Size(100, 60);

            return new ListBox { Size = size, Name = name };
        }

    } 
    #endregion

    #region GroupBox
    [Serializable]
    public class GroupBoxItem : BaseToolboxItem
    {
        public override Type ControlType
        {
            get { return typeof(GroupBox); }
        }

        public override string ControlName
        {
            get { return "GroupBox"; }
        }

        public override IconResourceHandle Icon
        {
            get
            {
                return new IconResourceHandle("Toolbox.Control_GroupBox.png");
            }
        }

        public override Control Create(string name)
        {
            var size = new System.Drawing.Size(150, 100);
            return new GroupBox { Size = size, Name = name };
        }

    }
    
    #endregion

    #region TreeView
    [Serializable]
    public class TreeViewItem : BaseToolboxItem
    {
        public override Type ControlType
        {
            get { return typeof(TreeView); }
        }

        public override string ControlName
        {
            get { return "TreeView"; }
        }

        public override IconResourceHandle Icon
        {
            get
            {
                return new IconResourceHandle("Toolbox.Control_TreeView.png");
            }
        }

        public override Control Create(string name)
        {
            TrackProperties.Add("Nodes");
            var size = new System.Drawing.Size(150, 230);
            var tree= new TreeView { Size = size, Name = name };
            return tree;
        }

    }
    
    #endregion

    #region ListView
    [Serializable]
    public class ListViewItem : BaseToolboxItem
    {
        public override Type ControlType
        {
            get { return typeof(ListView); }
        }

        public override string ControlName
        {
            get { return "ListView"; }
        }

        public override IconResourceHandle Icon
        {
            get
            {
                return new IconResourceHandle("Toolbox.Control_ListView.png");
            }
        }

        public override Control Create(string name)
        {
            TrackProperties.Add("Columns");
            var size = new System.Drawing.Size(200, 230);
            return new ListView { Size = size, Name = name };
        }

    }
    
    #endregion

}